//
//  CustView.m
//  haha
//
//  Created by lanou3g on 15/6/3.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "CustView.h"


@implementation CustView

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */
- (id)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self) {
        self.frame = frame;
        
        //创建imageView
        self.imagesView =[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        //设置自定义scrollerView属性
        self.minimumZoomScale = 1.0;
        self.maximumZoomScale = 1.5;
        self.bounces = NO;
        self.bouncesZoom = YES;
        self.clipsToBounds = YES;
        //设置imageView属性(根据比例展示在imageView上)
        _imagesView.clipsToBounds = YES;
        //添加imageView到自定义轮播视图
        [self addSubview:_imagesView];
        
        self.contentMode = UIViewContentModeScaleAspectFit;
        _imagesView.contentMode = UIViewContentModeScaleAspectFit;
        
        //        self.delegate = self;
    }
    return self;
}


//返回要缩放的视图

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return _imagesView;
}


////
//- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view
//{
//    self.contentMode = UIViewContentModeScaleAspectFit;
//}

- (void)scrollViewDidZoom:(UIScrollView *)scrollView
{
    
    if (self.zoomScale<1) {
        _imagesView.center =  CGPointMake(self.superview.frame.size.width/2, self.superview.frame.size.height/2);
    }
    NSLog(@"++frame === %.2f  %.2f",self.contentSize.width,self.contentSize.height);
}


//缩放结束
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale
{
    if (self.zoomScale<1.0) {//如果缩放比例大于1
        _imagesView.center =  CGPointMake(self.superview.frame.size.width/2, self.superview.frame.size.height/2);
    }
}




@end
